package com.adcok.lcdns.activity.notify.adapter;

import java.util.ArrayList;

import android.content.Context;
import android.graphics.Paint;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.adcok.lcdns.cronos.data.CNLottoAdFaQData;
import com.adcok.lcdns.cronos.datahandler.CNBaseDataSet;
import com.adcok.lcdns.R;

/**
 * FAQ Adapter
 * @author Administrator
 *
 */
public class LottoAdFaqAdapter extends BaseAdapter{

	private Context mContext;
	private int selectedPos = -1;
	
	protected LayoutInflater mInflater = null;
	protected ArrayList<CNBaseDataSet> mDataSetList = null;
	
	private class ViewHolder {
		ImageView mNotifyArrow;
		TextView mTitleTextView;
		TextView mContentsTextView;
	}
	
	public LottoAdFaqAdapter(Context context){
		this.mContext = context;
		this.mInflater = LayoutInflater.from(context);
	}
	
	public void setDataSetList(ArrayList<CNBaseDataSet> dataSetList) {
		this.mDataSetList = dataSetList;
	}
	
	public void clear(){
		if(this.mDataSetList != null){
			this.mDataSetList.clear();
			this.notifyDataSetChanged();
		}
	}
	
	@Override
	public int getCount() {
		if (this.mDataSetList != null) {
			return this.mDataSetList.size();
		}
		return 0;
	}

	@Override
	public Object getItem(int position) {
		if (this.mDataSetList != null) {
			return this.mDataSetList.get(position);
		}
		return null;
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		ViewHolder holder = null;
		if(convertView == null){
			convertView = this.mInflater.inflate(R.layout.lottoad_menu_notify_faq_row, null);
			holder = new ViewHolder();
			
			holder.mNotifyArrow = (ImageView) convertView.findViewById(R.id.imageView_arrow);
			holder.mTitleTextView = (TextView) convertView.findViewById(R.id.textView_title);
			holder.mContentsTextView = (TextView) convertView.findViewById(R.id.textView_contents);
			Log.e("BenTag", "before");
			Log.i("BenTag", holder.mTitleTextView == null?"mTitleTextView null":"mTitleTextView not null");
			holder.mTitleTextView.setPaintFlags(holder.mTitleTextView.getPaintFlags() | Paint.FAKE_BOLD_TEXT_FLAG);
			Log.e("BenTag", "after");
			
			convertView.setTag(holder);
		} else {
			holder = (ViewHolder) convertView.getTag();
		}
		
		CNLottoAdFaQData dataSet = (CNLottoAdFaQData) getItem(position);
		
		if(dataSet != null){
			
			holder.mTitleTextView.setText(dataSet.faqTitle);
			holder.mContentsTextView.setText(dataSet.faqContents);
			
			if(selectedPos == position){
				holder.mNotifyArrow.setBackgroundDrawable(mContext.getResources().getDrawable(R.drawable.info_down));
				holder.mContentsTextView.setVisibility(View.VISIBLE);
	        } else {
	        	holder.mNotifyArrow.setBackgroundDrawable(mContext.getResources().getDrawable(R.drawable.info_left));
	        	holder.mContentsTextView.setVisibility(View.GONE);
	        }
		}
		
		return convertView;
	}
	
	public void setSelectedPosition(int pos){
		selectedPos = pos;
		notifyDataSetChanged();
	}
}
